<?php
/**
 * Created by PhpStorm.
 * @description:
 * @time:
 * @Author: yfl
 * @QQ 554665488
 * Date: 2018-5-28
 * Time: 21:35
 */
$server = new Swoole\Server('127.0.0.1', 9501);
//添加一个用户自定义的工作进程。此函数通常用于创建一个特殊的工作进程，用于监控、上报或者其他特殊的任务。
//$process 为swoole_process对象，注意不需要执行start。在swoole_server启动时会自动创建进程，并执行指定的子进程函数
$process = new swoole_process(function ($process) use ($server) {

    while (true) {
        $msg=$process->read();

        foreach ($server->connections as $connection) {
            $server->send($connection,$msg);
        }
    }
});
$server->addProcess($process);
$server->on('receive',function ($serv,$fd,$from_id,$data)use($process){

        $process->write($data);
});
$server->start();